/*自定义--基础管理*/
import { routerRedux } from 'dva/router';
import * as LoginService from '../services/basics';

export default {
  namespace: 'manauser',
  state: {
    data: [],
  },
  effects: {
    //人员管理
    //员工分页查询
    *fetch_user({ payload }, { call, put }) {
      const response = yield call(LoginService.get,'/api/web/employee/getEmployeeList',payload); 
    	yield put({ type: 'save',payload: response.data.obj,});
    },
    /*查询机构树*/
    *fetch_organ_tree({ payload, callback }, { call, put }) {
      const response = yield call(LoginService.get,'/api/web/org/getOrgTreeList');
    	callback(response.data.res,response.data.obj);
    },
    //查询学校 select
    *fetch_ListByschoolselect({ payload,callback }, { call, put }) {  
      	const response = yield call(LoginService.post,'/api/web/school/getSchoolListByOrg'); 
    	callback(response.data.res,response.data.obj);
    },
    //查询权限 select
    *fetch_permissions({ payload,callback }, { call, put }) {  
      	const response = yield call(LoginService.post,'/api/web/role/slicedQueryRole'); 
    		callback(response.data.res,response.data.obj);
    },
    //查询员工 id
    *fetchId_user({ payload ,callback}, { call, put }) {
      const response = yield call(LoginService.get,'/api/web/employee/getEmployee',payload);
    	callback(response.data.res,response.data.obj);
    },
    //根据组织机构查询人员
    *fetch_org_user({ payload,callback }, { call, put }) {
      const response = yield call(LoginService.get,'/api/web/employee/getEmployeeList',payload); 
    	callback(response.data.res,response.data.obj);
    },
    //给角色分配员工 权限
    *fetch_org_userqx({ payload,callback }, { call, put }) {
      const response = yield call(LoginService.get,'/api/web/roleEmployee/insertRoleEmployeeList',payload); 
    	callback(response.data.res,response.data.resMsg);
    },
    //员工添加
    *add_user({ payload, callback }, { call, put }) {
      const response = yield call(LoginService.get,'/api/web/employee/insertEmployee', payload);
      callback(response.data.res,response.data.resMsg);
     	yield put({	type:'fetch_user',});
    },
    //员工信息修改
    *edit_user({ payload, callback }, { call, put }) {
      const response = yield call(LoginService.get,'/api/web/employee/updateEmployee', payload);
     	callback(response.data.res,response.data.resMsg);
     	yield put({	type:'fetch_user',});
     },
     *edit_user_state({ payload, callback }, { call, put }) {
      const response = yield call(LoginService.get,'/api/web/employee/updateStates', payload);
     	callback(response.data.res,response.data.resMsg);
     	yield put({type:'fetch_user',});
     },
     //员工批量删除
     *remove_user({ payload, callback }, { call, put }) {
      const response = yield call(LoginService.get,'/api/web/employee/deleteEmployeeByIds', payload);
      callback(response.data.res,response.data.resMsg);
      yield put({type:'fetch_user',});
    },
    //上传附件
    *imgurl({ payload, callback }, { call, put }) {
      const response = yield call(LoginService.get,'/api/web/attachment/upload', payload);
      callback(response.data.res,response.data.obj);
    },
  },
  reducers: {
    save(state, action) {
      return {
        ...state,
        data: action.payload,
      };
    },
  },
};
